import React, { useState, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { getToken } from "@/config/cookie";
import "./index.scss";

import illustration from '@/assets/images/login/illustration.svg'
import avatar from "@/assets/images/login/avatar.svg";

import LoginForm from './LoginForm';

/**
 * @description 登录页
 **/
function Login() {
  const navigate = useNavigate()

  useEffect(() => {
    const token = getToken()
    if (token) {
      navigate('/home')
    }
  }, [])

  return (
    <div className="login-page">
      <div className="login-bg">
        <img src={illustration} alt="" />
      </div>
      <div className="login-form-wrapper">
        <div className="form-center">
          <div className="form-title">
            <img src={avatar} alt="" />
            <h2>低碳数据管理与分析系统</h2>
          </div>
          <LoginForm />
        </div>
      </div>
    </div>
  );
}

export default Login;
